package com.ruoyi.testing.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.testing.domain.OaDispath;
import com.ruoyi.testing.service.IOaDispathService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 派工任务信息Controller
 * 
 * @author ruoyi
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/testing/dispath")
@Api(value="派工任务",tags = "派工任务")
public class OaDispathController extends BaseController
{
    @Autowired
    private IOaDispathService oaDispathService;

    /**
     * 查询派工任务信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value="派工任务列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    public TableDataInfo list(OaDispath oaDispath)
    {
        startPage();
        List<OaDispath> list = oaDispathService.selectOaDispathList(oaDispath);
        return getDataTable(list);
    }

    /**
     * 导出派工任务信息列表
     */
    @Log(title = "派工任务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaDispath oaDispath)
    {
        List<OaDispath> list = oaDispathService.selectOaDispathList(oaDispath);
        ExcelUtil<OaDispath> util = new ExcelUtil<OaDispath>(OaDispath.class);
        util.exportExcel(response, list, "派工任务信息数据");
    }

    /**
     * 获取派工任务信息详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取派工任务信息详细信息")
    @ApiImplicitParam(paramType="query", name = "id", value = "主键", required = true, dataType = "String")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(oaDispathService.selectOaDispathById(id));
    }

    /**
     * 获取统计派工消息信息
     */
    @GetMapping(value = "/getOaDispatch/count")
    @ApiOperation(value="获取统计派工消息信息")
    public AjaxResult getOaDispatchCount()
    {
        return success(oaDispathService.selectOaDispathCountByState(SecurityUtils.getLoginUser().getUser().getUserName()));
    }

    /**
     * 新增派工任务信息
     */
    @Log(title = "派工任务信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value="新增派工任务信息")
    public AjaxResult add(@ApiParam(name="派工任务信息",value="传入json格式",required=true) @RequestBody OaDispath oaDispath)
    {
        return toAjax(oaDispathService.insertOaDispath(oaDispath));
    }

    /**
     * 修改派工任务信息
     */
    @Log(title = "派工任务信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value="修改派工任务信息")
    public AjaxResult edit(@ApiParam(name="派工任务信息",value="传入json格式",required=true)@RequestBody OaDispath oaDispath)
    {
        return toAjax(oaDispathService.updateOaDispath(oaDispath));
    }

    /**
     * 删除派工任务信息
     */
    @Log(title = "派工任务信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation(value="删除派工任务信息")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oaDispathService.deleteOaDispathByIds(ids));
    }
}
